<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui">

    <ui:composition template="/template.xhtml">
        <ui:define name="title">
            <h:outputText value="#{bundle.ListFactoryTitle}"></h:outputText>
        </ui:define>
        <ui:define name="body">
            
            <!-- start of the login form -->
            
            <h:panelGroup id="messagePanel" layout="block">
                <h:messages errorStyle="color: red" infoStyle="color: green" layout="table"/>
            </h:panelGroup>
            
            <h:form class="well form-inline">
          
                <center>
                    <h1>اضافة مصنع جديد</h1>
                </center>
                
                <h:panelGrid columns="2">
                    <h:outputLabel value="#{bundle.CreateFactoryLabel_factoryName}" for="factoryName" />
                    <h:inputText id="factoryName" value="#{factoryController.selected.factoryName}" title="#{bundle.CreateFactoryTitle_factoryName}" required="true" requiredMessage="#{bundle.CreateFactoryRequiredMessage_factoryName}"/>
                    
                    <h:outputLabel value="#{bundle.CreateFactoryLabel_idcountry}" for="idcountry" />
                    <h:selectOneMenu id="idcountry" value="#{factoryController.selected.idcountry}" title="#{bundle.CreateFactoryTitle_idcountry}" required="true" requiredMessage="من فضلك إختر الدولة">
                        <f:selectItems value="#{countryController.itemsAvailableSelectOne}"/>
                    </h:selectOneMenu>
                </h:panelGrid>
                <div class="clear" ></div>
                
                <center>
                    <h:commandButton value="اضافه" action="#{factoryController.create}" class="btn btn-primary"  />
                </center>
                
            </h:form>

            <h:form >
                <center>
                    <h1>عرض المصانع</h1>
                </center>
                <h:outputText escape="false" value="#{bundle.ListFactoryEmpty}" rendered="#{factoryController.items.rowCount == 0}"/>
                <h:panelGroup rendered="#{factoryController.items.rowCount > 0}">
                    <p:dataTable value="#{factoryController.items}" var="item" 
                                 paginator="true" rows="10" 
                                 paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                                 rowsPerPageTemplate="10,20,30">

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListFactoryTitle_factoryName}"/>
                            </f:facet>
                            <h:outputText value="#{item.factoryName}"/>
                        </p:column>
                        
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListFactoryTitle_idcountry}"/>
                            </f:facet>
                            <h:outputText value="#{item.idcountry.countryName}"/>
                        </p:column>
                        
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="العملية"/>
                            </f:facet>
                            <h:commandLink action="#{factoryController.prepareView}" value="#{bundle.ListFactoryViewLink}" styleClass="btn btn-primary" />
                            <h:outputText value=" "/>
                            <h:commandLink action="#{factoryController.prepareEdit}" value="#{bundle.ListFactoryEditLink}" styleClass="btn btn-primary" />
                            <h:outputText value=" "/>
                            <h:commandLink action="#{factoryController.destroy}" value="#{bundle.ListFactoryDestroyLink}" styleClass="btn btn-primary" />
                        </p:column>
                    </p:dataTable>
                </h:panelGroup>
            </h:form>
        </ui:define>
    </ui:composition>

</html>
